package com.roadmap.common;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public abstract class RdcLogger {
	static {
		PropertyConfigurator.configure(getLog4jConfig());
		getLogger(RdcLogger.class).info("Logging configuration was completed");
	}

	public static Logger getLogger(Class clazz) {
		// logger.setLevel(level);
		return Logger.getLogger(clazz);
	}

	private static Properties getLog4jConfig() {
		Properties props = new Properties();
		try {
			props.load(new FileInputStream(BaseConst.CONFIG_LOCATION
					+ BaseConst.LOG_CONFIG_FILE));
			String path = BaseConst.getWebAppRealPath() + "logs/";
			File file = new File(path);
			if(!file.exists()) {
				file.mkdir();
			}
			path += props.getProperty("log4j.appender.R.File");
			props.setProperty("log4j.appender.R.File", path);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return props;
	}
}
